Assignemnt #103 and 103rd program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 103rd Program
///File name: Hund2prog.java
///Date Finished:3/30/2016
import java.util.Scanner;
public class Hund3prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner( System.in );
int choice, keychain = 0, keyPrice = 10, add, subtract, keychainsInOrder = 0;
double salesTax = 1.0825, shipping = 5 + (keychainsInOrder - 1);
System.out.println( "Ye old Keychain shoppe" );
System.out.println();
do
{
System.out.println( "1. Add keychains to order\n2. Remove Keychains from Order\n3. View current Order\n4. checkout" );
System.out.print( "Please enter your choice: " );
choice = keyboard. nextInt();
System.out.println();
if(choice == 1)
{
keychainsInOrder = addKeychains(keychainsInOrder);
System.out.println( "You now have " + keychainsInOrder + " keychains." );
}
else if(choice == 2)
{
keychainsInOrder = removeKeychains(keychainsInOrder);
System.out.println( "You now have " + keychainsInOrder + " keychains." );
}
else if(choice == 3)
{
viewOrder(keychainsInOrder, keyPrice, salesTax, shipping);
}
else if(choice == 4)
{
checkout(keychainsInOrder, keyPrice, salesTax, shipping);
}
else
{
System.out.println( "That's not a valid choice." );
}
}while (choice != 4);
}
public static int addKeychains(int keychain)
{
Scanner keyboard = new Scanner( System.in );
String x = "ADD KEYCHAINS";
int add;
System.out.print( "You have " + keychain + " keychains. How many to add? " );
add = keyboard.nextInt();
keychain = keychain + add;
if (keychain < 0)
keychain = 0;
return keychain;
}
public static int removeKeychains(int keychain)
{
Scanner keyboard = new Scanner( System.in );
String x = "REMOVE KEYCHAINS";
System.out.print( "You have " + keychain + " keychains. How many to remove? " );
int subtract = keyboard.nextInt();
keychain= keychain - subtract;
if(keychain < 0)
keychain = 0;
return keychain;
}
public static void viewOrder(int keychain, int keyPrice, double salesTax, double shipping)
{
String x = "VIEW ORDER" , message;
System.out.println( "You have " + keychain + " keychain.\n Keychains cost $10 each. \nTotal cost is " + ( keyPrice * keychain ));
}
public static void checkout(int keychain, int keyPrice, double salesTax, double shipping)
{
Scanner keyboard = new Scanner( System.in );
String x = "CHECKOUT" , check, name;
System.out.print( "What is your name? " );
name = keyboard.next();
viewOrder(keychain, keyPrice, salesTax, shipping);
System.out.println( "\nThanks for your order, " + name + "!" );
}
}
Picture of the output